package dome2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-09
 * Time: 16:17
 */
public class Student implements Comparable<Student> {
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    //重写Comparable接口的compareTo方法
    //缺点:不灵活!!
    public int compareTo(Student o) {
        //比较姓名:
        //此时这个compareTo调用的是name属性String的compareTo
//        if(this.name.compareTo(o.name) > 0) {
//            return 1;
//        }else if (this.name.compareTo(o.name) < 0) {
//            return -1;
//        }else {
//            return 0;
//        }

//        //比较年龄:
        if(this.age > o.age) {
            return 1;
        }else if (this.age < o.age) {
            return -1;
        } else {
            return 0;
        }
    }
}

